//
//  QJudgeBottomCell.m
//  QoilPublic
//
//  Created by 杨凯 on 16/7/7.
//  Copyright © 2016年 杨凯. All rights reserved.
//

#import "QJudgeBottomCell.h"
#import "QTagLabel.h"
@implementation QJudgeBottomCell{

    UILabel *badlabel;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self setSeparatorInset:UIEdgeInsetsZero];
        [self setLayoutMargins:UIEdgeInsetsZero];
        [self createUI];
    }
    return self;
}

- (void)createUI{
    
    UILabel *label = [QViewUtility createLabelWithFrame:CGRectMake((kScreenWidth-100)/2, 10, 100, 20) font:16 textAlignment:NSTextAlignmentCenter textColor:[UIColor blackColor] text:@"印象标签"];
    [self.contentView addSubview:label];

    _judgeArr = [NSMutableArray array];
    __block QJudgeBottomCell *wself = self;
    _tagView = [[QTagView alloc] init];
    _tagView.RequestBlock = ^(NSArray *arr){
        [wself.judgeArr removeAllObjects];
        for(QTagLabel *lab in arr){
            [wself.judgeArr addObject:lab.text];
        }
        if(wself.judgeBlock){
            wself.judgeBlock(wself.judgeArr);
        }
    };
    _tagView.frame = CGRectMake(0, label.bottom+10, kScreenWidth, 0);
    _tagView.width = kScreenWidth;
    self.tagView.tagLabelFont = [UIFont systemFontOfSize:16];
    self.tagView.tagLabelWidthPadding = 30;
    self.tagView.tagLabelHeightPadding = 15;
    self.tagView.tagLabelBorderWidth = 1.0f;
    self.tagView.tagLabelBorderColor = [QColorUtility defaultLineColor];
    self.tagView.tagLabelTextColor = [QColorUtility defaultDeepGrayColor];
    self.tagView.tagLabelCornerRadius = 2.0f;
    [self.contentView addSubview:_tagView];
    
    _badView = [[UITextView alloc] initWithFrame:CGRectMake(10, _tagView.bottom+10, kScreenWidth-20, 100)];
    _badView.hidden = NO;
    _badView.delegate = self;
    _badView.font = [UIFont systemFontOfSize:15];
    _badView.backgroundColor = [QColorUtility defaultBackGroundColor];
    [self.contentView addSubview:_badView];
    
    badlabel = [QViewUtility createLabelWithFrame:CGRectMake(10, 10, kScreenWidth-20, 16) font:Ksize15 textAlignment:NSTextAlignmentLeft textColor:[UIColor grayColor] text:@"请描述您不满意的地方"];
    [_badView addSubview:badlabel];

}

- (void)setDatas:(NSArray *)datas{
    _datas = datas;
    _tagView.titleArray = _datas;
    _tagView.frame = CGRectMake(0, 50, kScreenWidth, _tagView.viewHeight);
    _badView.frame = CGRectMake(10, _tagView.bottom+10, kScreenWidth-20, 100);
    if(_isBad){
        self.frame = CGRectMake(0, 0, kScreenWidth, _tagView.viewHeight+80+110);
    }else{
        self.frame = CGRectMake(0, 0, kScreenWidth, _tagView.viewHeight+80);
    }
}

- (void)setIsClick:(BOOL)isClick{
    _isClick = isClick;
    if(_isClick){
        _badView.userInteractionEnabled = YES;
       _tagView.userInteractionEnabled = YES;
        badlabel.hidden = NO;
    }else{
        _badView.userInteractionEnabled = NO;
        _tagView.userInteractionEnabled = NO;
        badlabel.hidden = YES;
    }
}

- (void)setIsBad:(BOOL)isBad{

    _isBad = isBad;
    if(_isBad){
        _badView.hidden = NO;
        [_badView becomeFirstResponder];
    }else{
        [_badView resignFirstResponder];
        _badView.hidden = YES;
    }
}

//评价详情数据
- (void)setDataDic:(NSDictionary *)dataDic{

    _dataDic = dataDic;
    
    NSString *labelContent = _dataDic[@"labelContent"];
    NSArray *arr = [labelContent componentsSeparatedByString:@","];
    if(arr.count == 0){
        arr = @[@"暂无"];
    }else{
        NSString *s = arr[0];
        if(s.length == 0){
            arr = @[@"暂无"];
        }
    }
    
    _tagView.titleArray = arr;
    _tagView.frame = CGRectMake(0, 50, kScreenWidth, _tagView.viewHeight);
    _badView.frame = CGRectMake(10, _tagView.bottom+10, kScreenWidth-20, 100);
    NSString *content = _dataDic[@"content"];
    
    if(content.length > 0){
       _badView.hidden = NO;
       _badView.text = content;
        self.frame = CGRectMake(0, 0, kScreenWidth, _tagView.viewHeight+80+110);
    }else{
        _badView.hidden = YES;
        self.frame = CGRectMake(0, 0, kScreenWidth, _tagView.viewHeight+80);
    }
}

#pragma mark --- textView delegate
- (void)textViewDidChange:(UITextView *)textView {
    if(textView.text.length == 0){
        badlabel.hidden = NO;
    }else{
        badlabel.hidden = YES;
    }
    if(self.badBlock){
        self.badBlock(textView.text);
    }
}


@end
